package com.cloudpivot.receivales.contract.entity.erpcontract;

import com.cloudpivot.receivales.contract.util.StrUtil;
import lombok.Data;

import javax.persistence.*;
import java.text.DecimalFormat;

/**
 * 合同明细表
 */
@Data
@Entity
@Table(name = "CM_Contract_Item_B")
public class CMContractItemB {

    @Transient
    private DecimalFormat dFormat = new DecimalFormat("#.00");
    /**
     * 传入必填字段
     */
    @Transient
    private String strCCode;    //产品类别
    @Column(name = "GUID")
    private String GUID;                //主表对应guid
    @Column(name = "strChief")
    private String strChief = ""; //上级

    @Column(name = "strName")
    private String strName;     //产品名称
    @Column(name = "dblQuantity")
    private double dblQuantity = 0.00; //数量
    @Column(name = "strMeasureUnit")
    private String strMeasureUnit = ""; //单位
    @Column(name = "dblTaxRatio")
    private float dblTaxRatio = 13; //税率
    @Column(name = "dblPrice")
    private double dblPrice; //含税原币单价

    @Id
    @Column(name = "ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int ID;       //主键,自增
    @Column(name = "intFlag")
    private int intFlag = 0;        //标志 0
    @Column(name = "strCode")
    private String strCode = "";     //产品顺序码
    @Column(name = "dblDiscountRatio")
    private String dblDiscountRatio = "100"; //折扣率
    @Column(name = "dblUntaxPrice")
    @Access(value = AccessType.PROPERTY)
    private double dblUntaxPrice = 0.0; //无税原币单价

    public double getDblUntaxPrice() {
        return StrUtil.returnHasTax(this.dblPrice, this.dblTaxRatio);
    }

    @Column(name = "dblUntaxPriceRMB")
    @Access(value = AccessType.PROPERTY)
    private double dblUntaxPriceRMB = 0.0; //无税本币单价

    public double getDblUntaxPriceRMB() {
        return StrUtil.returnHasTax(this.dblPrice, this.dblTaxRatio);
    }

    @Column(name = "dblPriceRMB")
    @Access(value = AccessType.PROPERTY)
    private double dblPriceRMB = 0.0; //含税本币单价

    public double getDblPriceRMB() {
        return this.dblPrice;
    }

    @Column(name = "dblUntaxSum")
    @Access(value = AccessType.PROPERTY)
    private double dblUntaxSum = 0.0; //无税原币金额

    public double getDblUntaxSum() {
        return this.dblUntaxPrice * this.dblQuantity;
    }

    @Column(name = "dblUntaxSumRMB")
    @Access(value = AccessType.PROPERTY)
    private double dblUntaxSumRMB = 0.0; //无税本币金额

    public double getDblUntaxSumRMB() {
        return this.dblUntaxPrice * this.dblQuantity;
    }

    @Column(name = "dblSum")
    @Access(value = AccessType.PROPERTY)
    private double dblSum = 0.00; //含税原币金额

    public double getDblSum() {
        return this.dblPrice * this.dblQuantity;
    }

    @Column(name = "dblSumRMB")
    @Access(value = AccessType.PROPERTY)
    private double dblSumRMB = 0.00; //含税本币金额

    public double getDblSumRMB() {
        return this.dblPrice * this.dblQuantity;
    }

    @Column(name = "dblUntaxExecSum")
    private double dblUntaxExecSum = 0.00; //0
    @Column(name = "dblUntaxExecSumRMB")
    private double dblUntaxExecSumRMB = 0.00; //0
    @Column(name = "dblExecSum")
    private double dblExecSum = 0.00; //0
    @Column(name = "dblExecSumRMB")
    private double dblExecSumRMB = 0.00; //0
    @Column(name = "dtStartDate")
    private String dtStartDate; // 合同开始日期
    @Column(name = "dtEndDate")
    private String dtEndDate; // 合同结束日期

    @Column(name = "strCorrSource")
    private String strCorrSource = "存货"; //对应明细来源--存货
    @Column(name = "strInvoiceID")
    @Access(value = AccessType.PROPERTY)
    private String strInvoiceID = ""; //对应存货编码

    public String getStrInvoiceID() {
        return this.strChief;
    }

    @Column(name = "strMemo")
    private String strMemo = ""; //备注
    @Column(name = "cDefine22")
    private String cDefine22 = "";
    @Column(name = "cDefine23")
    private String cDefine23 = "";
    @Column(name = "cDefine24")
    private String cDefine24 = "";
    @Column(name = "cDefine25")
    private String cDefine25 = "";
    @Column(name = "cDefine26")
    private String cDefine26 = "0"; //0
    @Column(name = "cDefine27")
    private String cDefine27 = "0"; //0
    @Column(name = "cDefine28")
    private String cDefine28 = "";
    @Column(name = "cDefine29")
    private String cDefine29 = "";
    @Column(name = "cDefine30")
    private String cDefine30 = "";
    @Column(name = "cDefine31")
    private String cDefine31 = "";
    @Column(name = "cDefine32")
    private String cDefine32 = "";
    @Column(name = "cDefine33")
    private String cDefine33 = "";
    @Column(name = "cDefine34")
    private String cDefine34 = "0"; //0
    @Column(name = "cDefine35")
    private String cDefine35 = "0"; //0
    @Column(name = "dblExecQuantity")
    private String dblExecQuantity = "0"; //执行数量 0
    @Column(name = "strXMDL")
    @Access(value = AccessType.PROPERTY)
    private String strXMDL = ""; //项目大类名称 demo:SJ01SJ01017,SJ01SJ01017,1

    public String getStrXMDL() {
        String strAppend = String.format("%s%s", getStrCCode(), getStrChief());
        return String.format("%s,%s,1", strAppend, strAppend);
    }

    @Column(name = "strContractID")
    private String strContractID = ""; //合同编号
    @Column(name = "intEnd")
    private int intEnd = 1; //是否末级 1
    @Column(name = "rowGUID")
    private String rowGUID; //guid
    /**
     * 自定义字段
     */
    @Column(name = "strSpare1")
    private String strSpare1 = "";
    @Column(name = "strSpare2")
    private String strSpare2;
    @Column(name = "strSpare3")
    private String strSpare3;
    @Column(name = "cFree1")
    private String cFree1 = "";
    @Column(name = "cFree2")
    private String cFree2 = "";
    @Column(name = "cFree3")
    private String cFree3 = "";
    @Column(name = "cFree4")
    private String cFree4 = "";
    @Column(name = "cFree5")
    private String cFree5 = "";
    @Column(name = "cFree6")
    private String cFree6 = "";
    @Column(name = "cFree7")
    private String cFree7 = "";
    @Column(name = "cFree8")
    private String cFree8 = "";
    @Column(name = "cFree9")
    private String cFree9 = "";
    @Column(name = "cFree10")
    private String cFree10 = "";
    @Column(name = "cInvDefine1")
    private String cInvDefine1 = "";
    @Column(name = "cInvDefine2")
    private String cInvDefine2 = ""; //
    @Column(name = "cInvDefine3")
    private String cInvDefine3 = ""; //
    @Column(name = "cInvDefine4")
    private String cInvDefine4 = ""; //
    @Column(name = "cInvDefine5")
    private String cInvDefine5 = ""; //
    @Column(name = "cInvDefine6")
    private String cInvDefine6 = ""; //
    @Column(name = "cInvDefine7")
    private String cInvDefine7 = ""; //
    @Column(name = "cInvDefine8")
    private String cInvDefine8 = ""; //
    @Column(name = "cInvDefine9")
    private String cInvDefine9 = ""; //
    @Column(name = "cInvDefine10")
    private String cInvDefine10 = ""; //
    @Column(name = "cInvDefine11")
    private String cInvDefine11 = "0"; //
    @Column(name = "cInvDefine12")
    private String cInvDefine12 = "0"; //
    @Column(name = "cInvDefine13")
    private String cInvDefine13 = "0"; //
    @Column(name = "cInvDefine14")
    private String cInvDefine14 = "0"; //
    @Column(name = "cInvDefine15")
    private String cInvDefine15; //
    @Column(name = "cInvDefine16")
    private String cInvDefine16; //
    @Column(name = "cInvStd")
    private String cInvStd = ""; //规格型号
    @Column(name = "cCusCode")
    private String cCusCode = ""; //客户编码
    @Column(name = "cVenCode")
    private String cVenCode = ""; //供应商编码
    @Column(name = "auxMeasureUnit")
    private String auxMeasureUnit = ""; //辅助计量编码
    @Column(name = "conversionRate")
    private String conversionRate; //换算率
    @Column(name = "pieceNum")
    private String pieceNum; //件数
    @Column(name = "execPieceNum")
    private double execPieceNum = 0.000000; //执行件数
    @Column(name = "decZbjRatio")
    private double decZbjRatio = 0.00; //0 质保金比例
    @Column(name = "cInvAddCode")
    private String cInvAddCode = "";
    @Column(name = "decNoRateZbjMoney")
    private double decNoRateZbjMoney = 0.000000; //0 质保金比例
    @Column(name = "decNoRateZbjBenBiMoney")
    private double decNoRateZbjBenBiMoney = 0.000000; //0 质保金比例
    @Column(name = "decZbjMoney")
    private double decZbjMoney = 0.000000; //0 质保金比例
    @Column(name = "decZbjBenbiMoney")
    private double decZbjBenbiMoney = 0.000000; //0 质保金比例
    @Column(name = "iAppIds")
    private int iAppIds = 0; //付款山清单字表id 0
    @Column(name = "cAppCode")
    private String cAppCode = "";
    @Column(name = "cItem_Class")
    private String cItem_Class = "";
    @Column(name = "cItemCCode")
    private String cItemCCode = "";
    @Column(name = "cItemName")
    private String cItemName = "";
    @Column(name = "iQuoids")
    private int iQuoids = 0; //报价单id 0
    @Column(name = "cQuoCode")
    private String cQuoCode = "";
    @Column(name = "cbsysbarcode")
    @Access(value = AccessType.PROPERTY)
    private String cbsysbarcode;
    public String getCbsysbarcode() {
       return  String.format("||cmco|%s", this.strContractID);    //条码 demo : ||cmco|ZJBSHT200617010|1 从行1开始
    }

    public CMContractItemB() {

    }
}
